//
//  Wi_Fi_Party_macOSTests.m
//  Wi-Fi Party macOSTests
//
//  Created by 许煜恒 on 2022/9/21.
//

#import <XCTest/XCTest.h>

#include "party-protocol.hpp"

@interface Wi_Fi_Party_macOSTests : XCTestCase
{
    Channel *test_channel;
    Receiver *test_receiver;
}

@end

@implementation Wi_Fi_Party_macOSTests

- (void)setUp {
    // Put setup code here. This method is called before the invocation of each test method in the class.
    int s=socket(AF_INET, SOCK_DGRAM, 0);
    
    int flag=1;
    //Reuse address (So the in-app recording could bind the same addr)
    if(setsockopt(s, SOL_SOCKET, SO_REUSEADDR,&flag,sizeof(flag))!=0){
        printf("Failed to enable address reuse\n");
    }
    
    self->test_channel=new Channel(3,channel_unreliable,1,s,[=](Packet *p){
        NSLog(@"From test_channel: %s",(char*)p->content.addr);
        return true;
    });

    
}

- (void)tearDown {
    // Put teardown code here. This method is called after the invocation of each test method in the class.
}

- (void)testExample {
    // This is an example of a functional test case.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
    char send_text[]="==========Test send text";
    self->test_channel->send(send_text, sizeof(send_text), 0);
}

- (void)testPerformanceExample {
    // This is an example of a performance test case.
    [self measureBlock:^{
        // Put the code you want to measure the time of here.
    }];
}

@end
